package com.ronghuanet.basic.service.impl;

import com.ronghuanet.basic.service.IBaiduAiService;
import com.ronghuanet.basic.util.AjaxResult;
import com.ronghuanet.basic.util.BaiduAuditUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

@Service
public class BaiduAiServiceImpl implements IBaiduAiService {
    @Override
    public AjaxResult audit(String text, String imgUrl, String videoUrl) {
        AjaxResult result = AjaxResult.me();
        StringBuilder sb = new StringBuilder();
        if (!StringUtils.isEmpty(text)) {
            Map<String, Object> textAuditResult =
                    BaiduAuditUtils.TextCensor(text);
            Boolean success = (Boolean) textAuditResult.get("success");
            String message = (String) textAuditResult.get("message");
            //只有失败我才做操作
            if (!success){
                result.setSuccess(false);
                sb.append(text+":"+message);
            }
        }

        if (!StringUtils.isEmpty(imgUrl)) {
            Map<String, Object> imgAuditResult =
                    BaiduAuditUtils.ImgCensor(imgUrl);
            Boolean success = (Boolean) imgAuditResult.get("success");
            String message = (String) imgAuditResult.get("message");
            if (!success){
                result.setSuccess(false);
                sb.append(imgUrl+":"+message);
            }
        }
        if (!StringUtils.isEmpty(videoUrl)) {
            //@TODO
        }

        if (!result.isSuccess())
            result.setMessage(sb.toString());
        return result;
    }
}
